package com.demo.minio.config;

import io.minio.MinioClient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


/**
 * @author lkz
 * @ClassName: MinioInit
 * @description: TODO
 * @date 2022/4/20 17:22
 */
@Component
@Data
public class MinioInit {

    @Value("${minio.url}")
    private String minioUrl;
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private  String  secretKey;
    @Value("${minio.bucket}")
    private String bucket;




    @Bean
    @ConditionalOnMissingBean
    public MinioClient minioClient(){
        MinioClient minioClient = MinioClient.builder().endpoint(minioUrl).
                credentials(accessKey, secretKey).build();
        return minioClient;
    }

}
